package com.gla.Controller;

import com.gla.common.Const;
import com.gla.common.ResponseCode;
import com.gla.domain.User;
import com.gla.domain.UserVO;
import com.gla.service.IUserService;
import com.gla.util.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
@RestController
public class UserController {
    @Autowired
    private IUserService userService;

    //修改个人信息
    @RequestMapping("/update_personInfo")
    public ServerResponse update(User user,HttpSession session){
        ServerResponse serverResponse = userService.updateUserLogic(user);
        //更新session中的用户信息
        if (serverResponse.isSuccess()){
            session.setAttribute(Const.CURRENT_USER,serverResponse.getData());
        }
        return serverResponse;
    }

    //修改个人信息
    @RequestMapping("/update_personName")
    public ServerResponse updateName(User user,HttpSession session){
        ServerResponse serverResponse = userService.updateUserName(user);
        //更新session中的用户信息
        if (serverResponse.isSuccess()){
            session.setAttribute(Const.CURRENT_USER,serverResponse.getData());
        }
        return serverResponse;
    }
}
